/*
    Developer: John Archer (john.archer.jpa@gmail.com)
 
    This file is part of VTBuilder.

    VTBuilder is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License.

    VTBuilder is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with VTBuilder.  If not, see <http://www.gnu.org/licenses/>.
 */

package core.sb;

import core.sb.s.Seq;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;

public class SB{
	
    public ArrayList <Seq> seqs;
    public int refLen;
    public SB(){seqs = new ArrayList <Seq> ();}
    
    public SB(Seq ir){
        this.seqs = new ArrayList<Seq>();
        this.seqs.add(ir);
    }
    
    //public SB(ArrayList <String> dna){
    //    this.seqs = new ArrayList<Seq>();
    //    for(int x=0; x<dna.size();x++){
    //        this.seqs.add(new Seq(dna.get(x)));
    //    }
    //}
    
    public SB(ArrayList <Seq> seqs){
        this.seqs = new ArrayList<Seq>();
        for(int x=0; x<seqs.size();x++){
            this.seqs.add(seqs.get(x));
        }
    }
    
    public Seq longest(){
    	Seq ir = seqs.get(0);
        for (int n = 1; n < seqs.size(); n++){
            if(ir.dna.length()<seqs.get(n).dna.length()){
            	ir = seqs.get(n);
            }
        }
        return ir;
    }

    public void sort(boolean decending){
        Collections.sort(seqs, new Seq());
        if(decending){
            Collections.reverse(seqs);
        }
    }
    
    public ArrayList <Seq> getSeqs(){return seqs; }
    
    public void save(String pathAndFname) throws Exception{
        PrintWriter outFile = new PrintWriter(new FileWriter(pathAndFname), false);
        for(int x=0; x<seqs.size(); x++){
            outFile.println(">"+seqs.get(x).title);
            outFile.println(seqs.get(x).dna);
        }
        outFile.close();
    }

}